/*
 * @Author: xiaosihan 
 * @Date: 2023-08-21 22:46:28 
 * @Last Modified by: xiaosihan
 * @Last Modified time: 2023-09-06 11:13:50
 */




import { autorun } from "mobx";
import { ReactNode, useEffect, useRef, useState } from "react";
import styles from "./toolUndo.module.less";
import undoSVG from "./undo.svg?raw";
import clsx from "clsx";
import { Tooltip } from "antd";
import designDataHistory from "@/editorComponent/designDataHistory";

interface Iprops {
}


// 后退
export default function ToolUndo() {

    const dom = useRef<HTMLDivElement | null>(null);
    const [data, setData] = useState({});
    const [disable, setDisable] = useState(true);
    const [undoNum, setUndoNum] = useState(0);

    useEffect(() => {

    }, []);

    useEffect(() => autorun(() => {
        const { undoNum } = designDataHistory.store;
        setUndoNum(undoNum);
    }), []);

    return (
        <Tooltip
            title="撤销(ctrl+z)"
            placement="bottom"
            mouseLeaveDelay={0}
            mouseEnterDelay={0.5}
        >
            <span
                className={clsx(styles.toolUndo, (undoNum === 0) && styles.disable)}
                dangerouslySetInnerHTML={{ __html: undoSVG }}
                onClick={(e) => {
                    designDataHistory.undo();
                }}
                onMouseUp={e=>{
                    e.stopPropagation();
                    e.preventDefault();
                }}
            >

            </span>
            {/* {undoNum} */}
        </Tooltip>
    );

}